package com.jarvis.pzz.modules.sellshop.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.jarvis.pzz.R;
import com.jarvis.pzz.modules.sellshop.model.SellPhotographModel;
import com.jarvis.pzz.util.ViewHolderUtil;

import java.util.List;

/**
 * Created by Administrator
 * on 2017/9/15.
 */

public class SellPhotographAdapter extends BaseAdapter {
    private List<SellPhotographModel> list;
    private Context context;

    public SellPhotographAdapter(List<SellPhotographModel> list, Context context) {
        this.context = context;
        this.list = list;
    }

    public void notifyDataSetChanged(List<SellPhotographModel> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final SellPhotographModel sellPhotographModel = list.get(position);
        convertView = LayoutInflater.from(context).inflate(R.layout.item_sellshop, null);
        ImageView imageView = ViewHolderUtil.get(convertView, R.id.img_sell);
        if (sellPhotographModel.getBitmap()!=null) {
            imageView.setImageBitmap(sellPhotographModel.getBitmap());
        } else {
            imageView.setImageResource(sellPhotographModel.getImg());
        }

        return convertView;
    }
}

